<template>
  <div id="BusinessSub">
    <div class="ge"></div>
    <div class="spinner geto" v-show="spinner">
      <div class="bounce1"></div>
      <div class="bounce2"></div>
      <div class="bounce3"></div>
    </div>          
    <div class="contentTwo-head" v-for="(item,index) in ContentTwo" :key="index">
        <div>
            <div class="contentTwo-left"><span>{{item.SERVERPART_NAME | dateEmpty}}</span></div>
            <div class="contentTwo-right">               
                <span>{{item.ACCEPT_CODE | dateState}}，{{item.HIGHWAYPROINST_NEXTID | dateState}}</span>
            </div>
            <br />
        </div>
        <div>
            <div class="contentTwo-name"><span class="contentTwo-text">{{item.DEPT_NAME | dateEmpty}}</span></div>
            <br />
        </div>
        <div>
            <div class="lie-left">申请人员：</div>
            <div class="lie_right"><span>{{item.STAFF_NAME | dateEmpty}}</span></div>
            <br />
        </div>					
        <div>
            <div class="lie-left">创建时间：</div>
            <div class="lie_right"><span>{{item.HIGHWAYPROINST_CREATEDATE | dateEmpty}}</span></div>
            <br />
        </div>
        <div>
            <div class="lie-left">审结时间：</div>
            <div class="lie_right"><span>{{item.HIGHWAYPROINST_ENDDATE | dateEmpty}}</span></div>
            <br />
        </div>  
        <div v-show="Toexamine" class="to-examine" @click="menuImg()">
            <img src="../../static/img/BusinessSub/ddsh.png" width="20%" /> 
            审核
        </div>              
        <div class="process" v-for="(item,i) in process" :key="i" v-show="proshow[i]">
          <img src="../../static/img/BusinessSub/sjq.png" width="6%" class="sjq" />
          <img src="../../static/img/BusinessSub/rl.png" width="4.5%" class="rl" />
          <div class="sjxian" v-show="sjshow[i]"></div>
          {{item.APPROVED_DATE | dateEmpty}}
          <p>【{{item.APPROVED_NAME | dateEmpty}}】{{item.APPROVED_STAFF | dateEmpty}}：{{item.APPROVED_INFO | dateEmpty}}；</p>
        </div> 
        <div class="xial" v-show="xial" @click="clickProshow()">
          <img src="../../static/img/xxiang.png" width="5%" />
        </div>       
        <div class="xial" v-show="shangl" @click="clickProshowS()">
          <img src="../../static/img/sxiang.png" width="5%" />
        </div>            
    </div>   
    <mt-popup v-model="PopupVisible3" position="">
        <div class="opinion">
            <p class="opinion-title">意见</p>
            <mt-field placeholder="" type="textarea" rows="4" class="PURCHASE-DESC" v-model="PURCHASEDESC" @input="desTextarea"></mt-field>
            <hr class="opinion-hr" />
        </div>
        <button class="buttton1" :class="disabledClass" v-bind:disabled="disabled" @click="examine()">通过</button>
        <button class="buttton2" :class="disabledClass" v-bind:disabled="disabled" @click="fallback()">驳回</button>
        <br />
    </mt-popup> 
    <p class="commodityP" v-text="commodityP"></p>
    <div class="commodity" v-for="(item,i) in commodity" :key="i">
      <p>{{item.COMMODITYTYPE_NAME | dateEmpty}} <s v-show="contrastCom(item.COMMODITYTYPE_NAME,item.F_COMMODITYTYPE_NAME)">{{item.F_COMMODITYTYPE_NAME | dateEmpty}}</s></p>
      <hr />
      <div class="commodityZ">
        <p>【商品名称】：{{item.COMMODITY_NAME | dateEmpty}} <s v-show="contrastCom(item.COMMODITY_NAME,item.F_COMMODITY_NAME)">{{item.F_COMMODITY_NAME | dateEmpty}}</s></p>  
        <p>【商品条码】：{{item.COMMODITY_BARCODE | dateEmpty}} <s v-show="contrastCom(item.COMMODITY_BARCODE,item.F_COMMODITY_BARCODE)">{{item.F_COMMODITY_BARCODE | dateEmpty}}</s></p>
        <p v-show="contrastCom(item.COMMODITY_UNIT,item.F_COMMODITY_UNIT)">【商品单位】：{{item.COMMODITY_UNIT | dateEmpty}} <s>{{item.F_COMMODITY_UNIT | dateEmpty}}</s></p>
        <p v-show="contrastCom(item.COMMODITY_RULE,item.F_COMMODITY_RULE)">【商品规格】：{{item.COMMODITY_RULE | dateEmpty}} <s>{{item.F_COMMODITY_RULE | dateEmpty}}</s></p>
        <p v-show="contrastCom(item.COMMODITY_STATE,item.F_COMMODITY_STATE)">【商品状态】：{{item.COMMODITY_STATE | ComState}} <s>{{item.F_COMMODITY_STATE | ComState}}</s></p>
        <p v-show="contrastCom(item.COMMODITY_ORIPRICE,item.F_COMMODITY_CURRPRICE)">【当前价格】：{{item.COMMODITY_ORIPRICE | ComMoney}} <s>{{item.F_COMMODITY_CURRPRICE | ComMoney}}</s></p>
        <p v-show="contrastCom(item.COMMODITY_RETAILPRICE,item.F_COMMODITY_RETAILPRICE)">【零售价格】：{{item.COMMODITY_RETAILPRICE | ComMoney}} <s>{{item.F_COMMODITY_RETAILPRICE | ComMoney}}</s></p>
        <p v-show="contrastCom(item.COMMODITY_PURCHASEPRICE,item.F_COMMODITY_PURCHASEPRICE)">【进货价格】：{{item.COMMODITY_PURCHASEPRICE | ComMoney}} <s>{{item.F_COMMODITY_PURCHASEPRICE | ComMoney}}</s></p>
        <p v-show="contrastCom(item.CANSALE,item.F_CANSALE)">【是否可售】：{{item.CANSALE | ComSell}} <s>{{item.F_CANSALE | ComSell}}</s></p>
        <p v-show="contrastCom(item.ISBULK,item.F_ISBULK)">【是否散装】：{{item.ISBULK | ComBulk}} <s>{{item.F_ISBULK | ComBulk}}</s></p>       
        <p v-show="contrastCom(item.METERINGMETHOD,item.F_METERINGMETHOD)">【称重方式】：{{item.METERINGMETHOD | ComWeigh}} <s>{{item.F_METERINGMETHOD | ComWeigh}}</s></p>
        <div v-show="effect"> 
          <div v-show="vaildShow[i]">
            【已生效收银机】：
            <div v-for="(vai,j) in infor1[i]" :key="j">
              <p class="store">{{j+1}}.{{vai.store}}</p>
              <p class="machine">{{vai.machine}}</p>
            </div>
          </div>
          <div v-show="invaildShow[i]">
            【未生效收银机】：
            <div v-for="(invai,k) in infor2[i]" :key="k">
              <p class="store">{{k+1}}.{{invai.store}}</p>
              <p class="machine">{{invai.machine}}</p>
            </div>
          </div>         
        </div>
      </div>
    </div>  
    <!-- 审核动画 -->
    <div class="trialani" v-show="trialani">
      <img :src="trialImg" alt="" width="45%">
      <p v-text="trialtext"></p>
    </div>
    <!-- end -->
  </div>
</template>
<script>
import store from "@/store/store.js";
import trialImg from "../../static/img/BusinessSub/33.png";
import trialImgT from "../../static/img/BusinessSub/complete.gif";
import trialImgF from "../../static/img/BusinessSub/completeF.gif";
import { Indicator, Field } from "mint-ui";
export default {
  name: "BusinessSub",
  data() {
    return {
      Url:
        // "http://mall.eshangtech.com:8010/MobileServicePlatform/Handler/handler_ajax.ashx?",
        "http://192.168.10.110:8010/MobileServicePlatform/Handler/handler_ajax.ashx?",
      Urls:
        // "http://mall.eshangtech.com:8010/MobileServicePlatform/Handler/handler_ajax.ashx?",
         "http://192.168.10.110:8010/MobileServicePlatform/Handler/handler_ajax.ashx?",
      ContentTwo: [],
      Toexamine: true,
      PopupVisible3: false,
      Opinion: "", //审核，回退意见
      projectIdS: [],
      projectId: "", //项目内码
      projectState: "", //业务状态
      WxId: "", //微信内码
      provinceCode: "", //省份编码
      serverpartId: "", //服务区内码
      commodity: [],
      trialani: false,
      trialtext: "",
      commodityP: "",
      trialImg: "../../static/img/BusinessSub/33.png",
      trialImgT: "../../static/img/BusinessSub/complete.gif",
      trialImgF: "../../static/img/BusinessSub/completeF.gif",
      spinner: true,
      PURCHASEDESC: "",
      process: [],
      processLength: "",
      disabled: true,
      disabledClass: "disabled",
      effect: false,
      vaildShow: [],
      invaildShow: [],
      sjshow: [],
      proshow: [],
      xial: false,
      shangl: false,
      infor1: [],
      infor2: []
    };
  },
  methods: {
    menuImg: function() {
      this.PURCHASEDESC = "";
      this.PopupVisible3 = !this.PopupVisible3;
    },
    // 意见非空验证
    desTextarea: function() {
      if (this.PURCHASEDESC != "") {
        this.disabled = false;
        this.disabledClass = "";
      } else {
        this.disabled = true;
        this.disabledClass = "disabled";
      }
    },
    // 审核
    examine: function() {
      this.Opinion = this.PURCHASEDESC;
      this.projectId = this.projectIdS[0];
      this.WxId = store.state.wxid;
      // alert(
      //   this.Opinion +
      //     "," +
      //     this.projectId +
      //     "," +
      //     this.projectState +
      //     "," +
      //     this.WxId +
      //     "," +
      //     this.provinceCode +
      //     "," +
      //     this.serverpartId
      // );
      this.PopupVisible3 = false;
      Indicator.open();
      this.$http
        .get(
          this.Url +
            "action_type=GetSubmitApprove&action_data=" +
            this.projectId +
            "&action_record=" +
            this.projectState +
            "&APPROVED_INFO=" +
            this.Opinion +
            "&MEMBERSHIP_ID=" +
            this.WxId +
            "&PROVINCE_CODE=" +
            this.provinceCode +
            "&SERVERPART_ID=" +
            this.serverpartId
        )
        .then(response => {
          Indicator.close();
          // success callback
          // alert(response.data);
          if (response.data == "1") {
            this.trialani = true;
            this.trialImg = trialImgT;
            this.trialtext = "审核通过";
            setTimeout(() => {
              this.trialani = false;
              this.trialImg = trialImg;
            }, 2000);
            this.loadContentTwo();
          } else {
            this.trialani = true;
            this.trialImg = trialImgF;
            this.trialtext = response.data;
            setTimeout(() => {
              this.trialani = false;
              this.trialImg = trialImg;
            }, 3000);
            this.loadContentTwo();
          }
        })
        .catch(error => {
          // console.log(error);
        });
    },
    // 回退
    fallback: function() {
      this.Opinion = this.PURCHASEDESC;
      this.projectId = this.projectIdS[0];
      this.WxId = store.state.wxid;
      this.PopupVisible3 = false;
      Indicator.open();
      this.$http
        .get(
          this.Url +
            "action_type=GetBackProinst&action_data=" +
            this.projectId +
            "&action_record=" +
            this.projectState +
            "&APPROVED_INFO=" +
            this.Opinion +
            "&MEMBERSHIP_ID=" +
            this.WxId +
            "&PROVINCE_CODE=" +
            this.provinceCode
        )
        .then(response => {
          Indicator.close();
          // success callback
          // alert(response.data);
          if (response.data == "1") {
            this.trialani = true;
            this.trialImg = trialImgT;
            this.trialtext = "驳回通过";
            setTimeout(() => {
              this.trialani = false;
              this.trialImg = trialImg;
            }, 2000);
            this.loadContentTwo();
          } else {
            this.trialani = true;
            this.trialImg = trialImgF;
            this.trialtext = response.data;
            setTimeout(() => {
              this.trialani = false;
              this.trialImg = trialImg;
            }, 3000);
            this.loadContentTwo();
          }
        })
        .catch(error => {
          // console.log(error);
        });
    },
    // 头部业务信息
    loadContentTwo: function() {
      this.$http
        .get(
          this.Url +
            "action_type=GetApproveInfo&action_data=" +
            this.projectIdS[0]
        )
        .then(response => {
          // success callback
          this.spinner = false;
          this.loadCommodity();
          this.ContentTwo = response.data.HIGHWAYPROINST;
          this.$http
            .get(
              this.Url +
                "action_type=GetApproveByID&action_data=" +
                this.projectIdS[0]
            )
            .then(response => {
              // success callback
              this.process = response.data.ALLAPPROVEDLIST;
              this.processLength = response.data.ALLAPPROVEDLIST.length;
              if (this.processLength > 3) {
                this.xial = true;
              }
              for (let i = 0; i < this.processLength; i++) {
                if (i == this.processLength - 1 || i == 2) {
                  this.sjshow[i] = false;
                } else {
                  this.sjshow[i] = true;
                }
                if (i < 3) {
                  this.proshow[i] = true;
                } else {
                  this.proshow[i] = false;
                }
              }
            })
            .catch(error => {
              // console.log(error);
            });
          this.projectState =
            response.data.HIGHWAYPROINST[0].HIGHWAYPROINST_NEXTID;
          if (this.projectState === "9000") {
            this.effect = true;
          }
          this.provinceCode = response.data.HIGHWAYPROINST[0].PROVINCE_CODE;
          this.serverpartId = response.data.HIGHWAYPROINST[0].DEPT_ID;
          if (
            response.data.HIGHWAYPROINST[0].HIGHWAYPROINST_NEXTID == 9000 ||
            response.data.HIGHWAYPROINST[0].HIGHWAYPROINST_NEXTID == 1000 ||
            this.projectIdS[1] == 1
          ) {
            this.Toexamine = false;
          } else if (
            response.data.HIGHWAYPROINST[0].HIGHWAYPROINST_NEXTID == 2000
          ) {
            //验证二审权限
            this.$http
              .get(
                this.Urls +
                  "action_type=GetModuleAuthority&action_data=" +
                  store.state.openid +
                  "&action_record=4ef21b1f-aada-49b7-9538-24df20dee1c7"
              )
              .then(response => {
                // success callback
                if (response.data.ModuleAuthorityObject.length == 0) {
                  this.Toexamine = false;
                } else {
                  this.Toexamine = true;
                }
              })
              .catch(error => {
                // console.log(error);
              });
          } else {
            if (response.data.HIGHWAYPROINST[0].APPROVED_STAFF != "&nbsp;") {
              //验证三审权限
              this.$http
                .get(
                  this.Urls +
                    "action_type=GetModuleAuthority&action_data=" +
                    store.state.openid +
                    "&action_record=994cca48-52a8-4164-bea1-7680fd65a400"
                )
                .then(response => {
                  // success callback
                  // console.log(response.data.ModuleAuthorityObject.length);
                  if (response.data.ModuleAuthorityObject.length == 0) {
                    this.Toexamine = false;
                  }
                })
                .catch(error => {
                  // console.log(error);
                });
            } else {
              //验证二审权限
              this.$http
                .get(
                  this.Urls +
                    "action_type=GetModuleAuthority&action_data=" +
                    store.state.openid +
                    "&action_record=4ef21b1f-aada-49b7-9538-24df20dee1c7"
                )
                .then(response => {
                  // success callback
                  if (response.data.ModuleAuthorityObject.length == 0) {
                    this.Toexamine = false;
                  }
                })
                .catch(error => {
                  // console.log(error);
                });
            }
          }
          if (response.data.HIGHWAYPROINST[0].ACCEPT_CODE === "100100") {
            this.commodityP = "商品新增详情";
          } else if (response.data.HIGHWAYPROINST[0].ACCEPT_CODE === "100200") {
            this.commodityP = "信息修改详情";
          } else {
            this.commodityP = "商品调价详情";
          }
          // console.log(response);
        })
        .catch(error => {
          // console.log(error);
        });
    },
    // 商品变更信息
    loadCommodity: function() {
      this.$http
        .get(
          this.Url +
            "action_type=GetApproveCommodity&action_data=" +
            this.projectIdS[0]
        )
        .then(response => {
          // success callback
          // console.log(response);
          this.commodity = response.data.COMMODITYLIST;
          let i = 0;
          response.data.COMMODITYLIST.forEach(val => {
            if (val.MACHINE_VAILD == "&nbsp;") {
              this.vaildShow[i] = false;
            } else {
              this.vaildShow[i] = true;
            }
            if (val.MACHINE_INVAILD == "&nbsp;") {
              this.invaildShow[i] = false;
            } else {
              this.invaildShow[i] = true;
            }
            let vaildS = val.MACHINE_VAILD.split("|");
            let casArr = new Array();    
            for (let j = 0; j < vaildS.length; j++) {
              let cas = vaildS[j].split("：");           
              let Obj = {};
              Obj.store = cas[0];
              Obj.machine = cas[1];
              casArr.push(Obj);
            }        
            this.infor1[i] = casArr;  
            let invaildS = val.MACHINE_INVAILD.split("|");
            let casArr2 = new Array();    
            for (let j = 0; j < invaildS.length; j++) {
              let cas2 = invaildS[j].split("：");                  
              let Obj2 = {};
              Obj2.store = cas2[0];
              Obj2.machine = cas2[1];
              casArr2.push(Obj2);
            }        
            this.infor2[i] = casArr2;              
            i++;
          });          
        })
        .catch(error => {
          // console.log(error);
        });
    },
    //商品信息对比
    contrastCom: function(com1, com2) {
      if (com1 == com2) {
        return false;
      } else {
        return true;
      }
    },
    clickProshow: function() {
      for (let i = 0; i < this.processLength; i++) {
        this.proshow[i] = true;
      }
      this.xial = false;
      this.shangl = true;
      this.sjshow[2] = true;
    },
    clickProshowS: function() {
      for (let i = 0; i < this.processLength; i++) {
        if (i > 2) {
          this.proshow[i] = false;
        }
      }
      this.xial = true;
      this.shangl = false;
      this.sjshow[2] = false;
    }
  },
  created() {
    this.projectIdS = this.$route.params.id.split(",");
    this.loadContentTwo();
    // alert(store.state.openid+","+store.state.wxid);
  }
};
</script>

<style scoped>
.ge {
  padding: 2.5rem 0 0 0;
}
.geto {
  padding: 1rem 0 0 0;
}
.contentTwo-head {
  width: 100%;
  margin: 0.5rem 0 0 0;
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  background-color: #fff;
  position: relative;
}
.contentTwo-left {
  width: 60%;
  float: left;
  height: 1.5rem;
  line-height: 1.5rem;
}
.contentTwo-right {
  width: 40%;
  float: left;
  height: 1.5rem;
  line-height: 1.5rem;
  text-align: right;
  padding-right: 1rem;
}
.contentTwo-name {
  float: left;
  height: 1.5rem;
  line-height: 1.5rem;
}
.contentTwo-text {
  font-size: 20px;
  color: #ec9061;
}
.lie-left {
  width: 18%;
  float: left;
  height: 1.5rem;
  line-height: 1.5rem;
}
.lie_right {
  width: 82%;
  float: left;
  height: 1.5rem;
  line-height: 1.5rem;
}
.to-examine {
  width: 15%;
  height: 1.5rem;
  line-height: 1.5rem;
  float: right;
  position: relative;
  z-index: 100;
}
.opinion {
  width: 15rem;
  padding: 15px 10px;
  text-align: center;
  border-bottom: 1px solid #dedede;
  border-radius: 2px 2px 0 0;
}
.opinion-title {
  font-size: 16px;
}
.PURCHASE-DESC {
  width: 100%;
  border: none #fff;
  background: transparent;
  outline: none;
  color: #000;
}
.opinion-hr {
  width: 100%;
  color: black;
  margin: 0.35rem auto;
}
.buttton1 {
  width: 50%;
  background-color: #4c4b5b;
  border: none;
  height: 2.25rem;
  color: #fff;
  float: left;
}
.buttton2 {
  width: 50%;
  background-color: #ec9061;
  border: none;
  height: 2.25rem;
  color: #fff;
  float: left;
}
.disabled {
  opacity: 0.3;
}
.commodityP {
  color: #b7b8ba;
  padding: 0.5rem;
}
.commodity {
  width: 100%;
  background-color: #fff;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
}
.commodityZ {
  padding: 0.5rem;
}
.trialani {
  width: 10rem;
  height: 6rem;
  box-shadow: 0px 1px 8px 0.2px #e2e2e2;
  text-align: center;
  background-color: #fff;
  position: fixed;
  top: 42%;
  left: 50%;
  -webkit-transform: translate3d(-50%, -50%, 0);
  -moz-transform: translate3d(-50%, -50%, 0);
  -o-transform: translate3d(-50%, -50%, 0);
  -ms-transform: translate3d(-50%, -50%, 0);
  transform: translate3d(-50%, -50%, 0);
}
.process {
  padding: 0.5rem;
  margin-bottom: 0.2rem;
  margin-left: 2rem;
  position: relative;
}
.sjq {
  position: absolute;
  top: 0.35rem;
  left: -2.1rem;
}
.rl {
  position: absolute;
  top: 0.45rem;
  left: -0.5rem;
}
.sjxian {
  width: 1px;
  height: 2.65rem;
  float: left;
  background: #fc9153;
  position: absolute;
  top: 1rem;
  left: -1.65rem;
}
.xial {
  text-align: center;
}
.store{
  margin-left: 0.5rem;
}
.machine{
  margin-left: 1rem;
}
</style>

